﻿using System;

namespace DynamicMVVMSL
{
    class Program
    {
        static void Main(string[] args)
        {
            var model = new TestModel {Id = 1, Name = "Hasmukh", Address = "1, Abc road, abc, ac12cd"};

            var obj = DynamicObjectCreator.CreateDynamicModel(model);

            var objType = obj.GetType();
            Console.WriteLine(objType.FullName);

            objType.GetProperty("Name").SetValue(obj,"Hasmukh Patel",null);
            
            var currVal = objType.GetProperty("Name").GetValue(obj, null);
            
            Console.WriteLine(currVal);

            foreach (var info in objType.GetProperties())
            {
                Console.WriteLine(info.Name);
            }

        }
    }


    public class TestModel
    {

        public int Id { get; set; }

        public string Name { get; set; }

        public string Address { get; set; }

    }

    public class TestClassBase
    {
        protected bool IsLoading;

        public int Age { get; set; }
    }

    public class TestClass2 : TestClassBase
    {
        public TestModel Model { get; private set; }

        public TestClass2(TestModel model)
        {
            Model = model;
            _id = model.Id;
        }

        private int _id;
        public int Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;

                if (!IsLoading)
                {
                    Model.Id = _id;
                    
                }
            }
        }
    }

}
